package com.ymatou.iapi.godmch.testcase;

import org.json.JSONException;
import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.godmch.parameter.createmchBean;
import com.ymatou.iapi.godmch.parameter.disableProviderBean;
import com.ymatou.iapi.godmch.service.disableProviderCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.serviceProvider;
import com.ymttest.database.sqlwapper.godmch.serviceProviderWapper;
/**
*禁用服务商
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_disableProvider{
	private static disableProviderBean bean;
	private static disableProviderCall call;
	private serviceProviderWapper serviceWapper=new serviceProviderWapper();
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("禁用服务商");
	}

	@Before
	public void caseUp() {
		bean=new disableProviderBean();
		call=new disableProviderCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	private void check_verify(int providerId) throws  JSONException, InterruptedException
	{
		Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
		Logger.verifyEquals(true, call.getMessage().contains("请求成功"), "验证msg");
		Logger.verifyEquals(true, call.getSuccess(), "验证success");
		//验证数据库
		Logger.comment("##### 验证serviceProvider表 ######");
		serviceProvider service=serviceWapper.selectByPrimaryKey(providerId);
		Logger.verifyEquals(-1, service.getState(), "验证数据库serviceProvider 中的state=-1字段");
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_disableProvider_001() {
		Logger.start(true,"正例-禁用服务商");
		try {
			
			createmchBean pBean=GodmchManageCallService.InitAddProvider();
			int providerId=pBean.getMchId();
			bean.setProviderId(providerId);
			call.setData(bean);
			call.callService();		
			
			check_verify(providerId);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_disableProvider_002() {
		Logger.start(true,"反例-禁用服务商-服务商不存在(这个接口应该返回失败的,与研发沟通，暂时不更改)");
		try {
			
			bean.setProviderId(99);
			call.setData(bean);
			call.callService();			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}